feat: Implement int_from_ascii for NonZero<T>#152267
Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom Feb 7, 2026
Merged
feat: Implement int_from_ascii for NonZero<T>#152267rust-bors[bot] merged 1 commit intorust-lang:mainfrom
int_from_ascii for NonZero<T>#152267rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Conversation
Collaborator
|
r? @scottmcm rustbot has assigned @scottmcm. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Contributor
Author
|
@rustbot label +T-libs-api -T-libs |
Member
|
@bors r+ |
Contributor
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Feb 7, 2026
…scii, r=dtolnay feat: Implement `int_from_ascii` for `NonZero<T>` - Tracking issue: rust-lang#134821 This pull request adds `from_ascii` and `from_ascii_radix` methods to `NonZero<T>` that parses a non-zero integer from an ASCII-byte slice (`&[u8]`) with decimal digits or digits in a given base. When using the combination of `int::from_ascii` or `int::from_ascii_radix` and `NonZero::<T>::new`, [`IntErrorKind::Zero`](https://doc.rust-lang.org/core/num/enum.IntErrorKind.html#variant.Zero) cannot be returned as an error. `NonZero::<T>::from_str_radix` and `NonZero::<T>::from_str` require a string (`&str`) as a parameter. ```rust // Cannot return `IntErrorKind::Zero` as an error. assert_eq!(NonZero::new(u8::from_ascii(b"0").unwrap()), None); // Can return `IntErrorKind::Zero` as an error. let err = NonZero::<u8>::from_ascii(b"0").unwrap_err(); assert_eq!(err.kind(), &IntErrorKind::Zero); ``` See also rust-lang#152193
7 tasks
rust-bors bot
pushed a commit
that referenced
this pull request
Feb 7, 2026
…uwer Rollup of 8 pull requests Successful merges: - #148590 (Stabilize `atomic_try_update`and deprecate `fetch_update` starting 1.99.0) - #150522 (Stabilize new inclusive range type and iterator type) - #152235 (Convert to inline diagnostics in `rustc_parse`) - #152267 (feat: Implement `int_from_ascii` for `NonZero<T>`) - #151576 (Stabilize `core::hint::cold_path`) - #151933 (Linker-plugin-based LTO: give an explanation how to use linker-plugin-lto with full LTO) - #152010 (Ignore all debuginfo tests for LLDB that we do not run in CI) - #152199 (Move `rustc_query_system::cache`.)
rust-timer
added a commit
that referenced
this pull request
Feb 7, 2026
Rollup merge of #152267 - sorairolake:feature/nonzero-from-ascii, r=dtolnay feat: Implement `int_from_ascii` for `NonZero<T>` - Tracking issue: #134821 This pull request adds `from_ascii` and `from_ascii_radix` methods to `NonZero<T>` that parses a non-zero integer from an ASCII-byte slice (`&[u8]`) with decimal digits or digits in a given base. When using the combination of `int::from_ascii` or `int::from_ascii_radix` and `NonZero::<T>::new`, [`IntErrorKind::Zero`](https://doc.rust-lang.org/core/num/enum.IntErrorKind.html#variant.Zero) cannot be returned as an error. `NonZero::<T>::from_str_radix` and `NonZero::<T>::from_str` require a string (`&str`) as a parameter. ```rust // Cannot return `IntErrorKind::Zero` as an error. assert_eq!(NonZero::new(u8::from_ascii(b"0").unwrap()), None); // Can return `IntErrorKind::Zero` as an error. let err = NonZero::<u8>::from_ascii(b"0").unwrap_err(); assert_eq!(err.kind(), &IntErrorKind::Zero); ``` See also #152193
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
int_from_ascii#134821This pull request adds
from_asciiandfrom_ascii_radixmethods toNonZero<T>that parses a non-zero integer from an ASCII-byte slice (&[u8]) with decimal digits or digits in a given base.When using the combination of
int::from_asciiorint::from_ascii_radixandNonZero::<T>::new,IntErrorKind::Zerocannot be returned as an error.NonZero::<T>::from_str_radixandNonZero::<T>::from_strrequire a string (&str) as a parameter.See also #152193